<%@ page import="javax.servlet.http.HttpSession" %>

<jsp:useBean id="signIn" scope="session" class="com.cseg674.dataquery.authentication.SignIn" />
<jsp:setProperty name= "signIn"  property="*"/>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<%@ include file="/includes/head.jsp" %>

<body>

<div id="page">

	<%@ include file="/includes/header.jsp" %>
	
	<div id="menulinks">
		<a href="index.jsp"><span>Home</span></a>	
		<div class="menulines"></div>
		<a href="about.jsp"><span>About</span></a>
		<div class="menulines"></div>
		<a href="entry.jsp"><span>Entry</span></a>
		<div class="menulines"></div>
		<a href="query.jsp"><span>Query</span></a>
		<div class="menulines"></div>
		<a href="login.jsp"><span>Login</span></a>
		<div class="menulines"></div>
		<a href="engineers.jsp"><span>Engineers</span></a>
		<div class="menulines"></div>
	</div>
	
	<div id="mainarea">
		<div id="contentarea">
			<h2>USER LOGIN</h2>
			<div class="content">
				<%
					if (signIn.getAction() != null){
						if(!signIn.validate()){
							//response.sendRedirect("login_error.jsp");
						}
						if(signIn.SignIn()){
							String userName = request.getParameter("username");
							out.println(" <center>" + userName + "Login successful!</center>"); 
							//start a session
							HttpSession session_login = request.getSession(true);
							session_login.setAttribute("username", userName);		
							response.sendRedirect("entry.jsp");							
						}else{
							out.println("<center>Invalid username or password!</center>");  
						}
					}else{    
				%>   
				<center>
					<div align="center"><img src="images/lock.png" alt="User Login" /></div>
					<h3>CSE G674 Portal</h3>
					<form action="<%=request.getRequestURI()%>" method="post">
						<input type="hidden" name="action" value="login">
						<table>
							<tr>
								<td width="100px"><p><b>Username:</b></p></td>
								<td width="200px"><input name="username" type="text" style="width:200px" /></td>
							</tr>
							<tr>
								<td width="100px"><p><b>Password</b></p></td>
								<td width="200px"><input name="password" type="password" style="width:200px" /></td>
							</tr>
							<tr>
								<td>&nbsp;</td>
								<td><input type="submit" value="login" style="width:200px" /></td>
							</tr>
						</table>
					</form>
				</center>
				<p>
					<a href="password.jsp"><font color="blue">Forgot your password?</font></a>
					<br>
					<a href="register.jsp"><font color="blue">Register for an account?</font></a>
				</p>

			  <% } %> 

			</div>
		
		</div>
	
		<%@ include file="/includes/sidebar.jsp" %>
		<%@ include file="/includes/footer.jsp" %>
	</div>

</body>

</html>